const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    entry: path.join(__dirname, './src/index.tsx'),
    output: {
        filename: 'bundle.js',
        path: path.join(__dirname, './dist')
    },
    resolve: {
        extensions: ['.js', '.jsx', '.ts', '.tsx']
    },
    module: {
        rules: 
        [
            {
                test: /\.(jsx|js|ts|tsx)$/,
                include: path.resolve(__dirname, './src'),
                exclude: /node_modules/,
                loader: 'eslint-loader',
                enforce: 'pre'
            },
            {
                test: /\.ts(x?)$/,
                include: path.join(__dirname, './src'),
                loader: 'awesome-typescript-loader'
            },
            {
                test: /\.less$/,
                include: path.join(__dirname, './src'),
                use: [
                    'style-loader',
                    'css-loader',
                    'postcss-loader',
                    'less-loader'
                ]
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                use: [{
                    loader: 'url-loader',
                    options: {
                        //1024 == 1kb  
                        //小于10kb时打包成base64编码的图片否则单独打包成图片
                        limit: 10240,
                        name: path.join('img/[name].[hash:7].[ext]')
                    }
                }]
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                use: [{
                    loader: 'url-loader',
                    options: {
                        limit: 10240,
                        name: path.join('font/[name].[hash:7].[ext]')
                    }
                }]
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: 'public/index.html',
            inject: true
        })
    ],
    devServer: {
        contentBase: path.join(__dirname, 'dist'),
        compress: true,
        port: 3000
    },
    performance: {
        hints: false
    }
}